<%@ include file="/common/taglibs.jsp"%>
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	     <title>路由信息管理</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<link rel="stylesheet" type="text/css" href="<%=basePath%>CSS/layout.css" />
</head>
<body>
<div id="wrapper">
    <!--头部菜单开始-->
    <jsp:include page="/common/head.jsp"></jsp:include>
    <!--头部菜单结束-->
	<div id="BreadCrumb">我的位置：基本资料管理 &gt; 路由信息管理</div>
	<div id="REC_content">
	    <fieldset id="BasicInfo" class="mainField">
		    <legend><span class="title">路由信息管理</span></legend>
			<div class="innerCon">
			    <div class="mainSearchBox">
			      <form action="route.do" method="post" >
			       <table width="100%" cellpadding="0" cellspacing="0" border="0" class="editTab">
					<tr height="35">
					  <td width="100" class="title"> 路由类型名称</td>
					  <td align="left"><input type="text" id="routeType" name="routeType"/>
						  <input type="submit" name="searchButton" class="newSearchButton" value="保存" /> 
						  <input type="reset" name="searchButton" class="newSearchButton" value="重置" onclick="restAll()"/> 
						</td>
					</tr>
					        
                   <c:forEach var="ws" items="${dataList}" varStatus="idx">
                       <input id="routeH${idx.index+1}" name="routeSname" type="hidden" />
                       <tr height="35">
					      <td width="80" class="title"> 工序路由${idx.index+1}</td>
					      <td align="left">
					         <select <c:if test="${idx.index > 0}">disabled=disabled</c:if> id="route${idx.index+1}" name="routeName" onchange="changeSelect(${idx.index+1})">
                                 <option></option>
                                 <c:if test="${idx.index eq 0}">
                                    <c:forEach var="ws1" items="${dataList}">
                                       <option value="${ws1.wsId}">${ws1.wsName}</option>
                                    </c:forEach>
                                 </c:if>
                             </select>
                          </td>
					   </tr>
                     </c:forEach>
				</table>
				</form>
			    
			    </div>
			    <!-- begin tab -->
			    <div class="topControl clearfix">
				    <div id="JobsMgrTabCon" class="itemTabCon">
					    <ul id="JobsMgrTabs" class="itemTabs">
							<li id="dueTab" class="blur"><a href="<%=basePath%>staff.do">员工信息管理</a></li>
							<li id="dueTab" class="blur"><a href="<%=basePath%>ws.do">工序信息管理</a></li>
							<li id="dueTab" class="focus"><a href="<%=basePath%>route.do"  onfocus="this.blur()">路由设置管理</a></li>
					    </ul>
				    </div>
			    </div>
			    <!-- end tab -->
				<div id="mainListCon">
				    <div id="mLC">
					    <ul>
						    <li>
							    <table width="888" style="border:1px solid #eee;" cellpadding="0" cellspacing="1" id="dataTable">
								    <tr bgcolor="#f2f6f9">
								        <td width="5%">序号</td>
									    <td width="30%">路由名称</td>
										<td width="30%"></td>
									</tr>
									<c:forEach var="typeName" items="${routeTypes}" varStatus="idx">
									<tr class="${idx.index%2==0?'list1':'list2'}" id="${idx.index+1}">
								     	<td>${idx.index+1}</td>
										<td><a style="cursor:hand" onclick="getRouteSetting('${typeName}')"><b>${typeName}</b></a></td>
										<td>
										  <input name="" class="newSearchButton" type="button" class="btn" value="删除" onclick="delRoute('${typeName}')"/>
									    </td>
									</tr>
									</c:forEach>
								</table> 
							</li>
						</ul>
					</div>
					<div id="result">
					</div>
				</div>
			</div>
		</fieldset>
	</div>
	<jsp:include page="/common/foot.jsp"></jsp:include>
</div>
    <script type="text/javascript" src="<%=basePath%>js/jquery.js"language="javascript"></script>
	<script src='<%=basePath%>dwr/interface/routeService.js'></script>
    <script src="<%=basePath%>dwr/engine.js"></script>
    <script type="text/javascript" language="javascript">
    var ary = new Array();
       <c:forEach var="wsD" items="${dataList}">
          ary[${wsD.wsId}]="${wsD.wsName}";
       </c:forEach>
           
       function delRoute(routeType){
           if($.trim(routeType)!=""){
            if(confirm("确定要删除("+routeType+")设置吗？")){
             routeService.delRoute(routeType);
             alert("删除成功!");
             window.location.reload();
            }
           }else{
             alert("请选择要删除的路由设置！");
           }
       }
       
       function changeSelect(num){
         var sValue=$("#route"+num).val();
         if(sValue=="")return;
         var ary2 = ary;
         $("#route"+num).attr("disabled","disabled");
         $("#routeH"+num).val(sValue);
         $("#route"+(num+1)).removeAttr("disabled");
         $("select[name='routeName']").each(function(i,d){
           if(i<num){
           delete ary2[this.value];
           }
         });
         var optionSelected="<option></option>";
         for ( var i=0 ; i < ary2.length ; ++i ){ 
           if(typeof ary2[i] == 'undefined')continue;
           optionSelected+="<option value="+i+">"+ary2[i]+"</option>";
         }
         $("#route"+(num+1)).empty();
         $("#route"+(num+1)).append(optionSelected);
       }
       
       function restAll(){
         window.location.reload();
       }
       
       function getRouteSetting(routeType){
         var tableResult = "<table style='border:1px solid #eee;' cellpadding='0' cellspacing='1' width='100%'>";
         var appendResult = "";
         var celled="";
         routeService.getRouteByRouteType(routeType,function(data){
           celled="<tr>";
           appendResult = "<tr>";
           var i=0;
           for(var property in data){ 
             i++;
             celled+="<td>"+(parseInt(property)+1)+"</td>";
             appendResult+="<td>"+data[property].wsName+"</td>";
           }
           celled+="</tr>";
           appendResult+="</tr>";
           tableResult+="<tr><td colspan="+(i)+"><b>"+routeType+"</b></td></tr>";
           tableResult+=celled;
           tableResult+=appendResult;
           tableResult+="</table>";
           $("#result").empty();
           $("#result").append(tableResult);
         });
       }
     </script>
  </body>
</html>
